<?php
declare(strict_types=1);

namespace App\Controller\Client;


use App\Controller\AbstractController;
use App\Request\Client\Login\LoginUseCaptchaRequest;
use App\Request\Client\Login\LoginUsePasswordRequest;
use App\Request\Client\Login\LoginUseWxMpRequest;
use App\Request\Client\Login\RegisterUseWxRequest;
use App\Service\Client\LoginService;
use Hyperf\Di\Annotation\Inject;

class LoginController extends AbstractController
{
    /**
     * @Inject()
     * @var LoginService
     */
    protected $loginService;

    /**
     * 手机验证码登录，如果用户不存在则创建
     * @param LoginUseCaptchaRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function loginUseCaptcha(LoginUseCaptchaRequest $request)
    {
        $validator = $request->validated();
        $data = $this->loginService->loginUseCaptcha($validator);
        return $this->response->success($data);
    }

    /**
     * 手机密码登录
     * @param LoginUsePasswordRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function loginUsePassword(LoginUsePasswordRequest $request)
    {
        $validator = $request->validated();
        $data = $this->loginService->loginUsePassword($validator);
        return $this->response->success($data);
    }



    /**
     * 微信快捷登录
     * @param LoginUseWxMpRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     */
    public function loginUseWx(LoginUseWxMpRequest $request)
    {
        $validator = $request->validated();
        $data = $this->loginService->loginUseWx($validator);
        return $this->response->success($data);
    }

    /**
     * 微信注册/绑定且登录
     * @param RegisterUseWxRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function registerUseWx(RegisterUseWxRequest $request){
        $validator = $request->validated();
        $data = $this->loginService->registerUseWx($validator);
        return $this->response->success($data);
    }


}